package com.gome.transactiontree;

import com.gome.transactiontree.api.Transaction;

/**
 * 
 * @author haqiaolong
 */
public class TransactionContextHolder {
	
	private static final ThreadLocal<Transaction> transactionCache = new ThreadLocal<Transaction>();
	
	public static void set(Transaction transaction) {
		transactionCache.set(transaction);
	}
	
	public static void remove() {
		transactionCache.remove();
	}
	
	public static Transaction current() {
		return transactionCache.get();
	}
	
	public static void setRollbackOnly() {
		Transaction transaction = current();
		if (transaction != null) {
			transaction.setRollbackOnly();
		}
	}
}